package sf.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

import sf.view.StandardForm;

public class ActionIzmena extends SFAbstractAction {

	private static final long serialVersionUID = 1L;
	
	private StandardForm parentForm;

	ActionIzmena(StandardForm parentForm) {
		this.parentForm = parentForm;
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK));
		putValue(MNEMONIC_KEY, KeyEvent.VK_I);
		putValue(SMALL_ICON, loadIcon("img/izmena.png"));
		putValue(NAME, "Izmena");
		putValue(SHORT_DESCRIPTION, "Izmena");
	}

	public void actionPerformed(ActionEvent e) {
		if ((parentForm.getMode()&StandardForm.MODE_EDIT) == 0) {
			parentForm.setMode(StandardForm.MODE_EDIT);
			
			int selectedRow = parentForm.getBrowser().getSelectedRow();
			
			if (selectedRow == -1)
				parentForm.getBrowser().setSelectedRow(-1);
			else
				parentForm.getController().processRowSelectionChanged(null);
			
			parentForm.getDetailsPane().lockPKFields();
			
			parentForm.getDetailsPane().getToolbar().removeAll();
			parentForm.getDetailsPane().getToolbar().add(parentForm.getActionManager().getPotvrdaIzmeneAction());
			parentForm.getDetailsPane().getToolbar().add(parentForm.getActionManager().getPonistiAction());
		}
	}
}
